package cn.lumin.mock.domain;

import com.cutefool.dsl.mybatis.core.objects.BasicsDomain;
import com.fasterxml.jackson.annotation.JsonAlias;
import jakarta.annotation.Generated;
import java.math.BigDecimal;
import java.sql.JDBCType;
import java.time.LocalDateTime;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.UnaryOperator;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.mybatis.dynamic.sql.SqlBuilder;
import org.mybatis.dynamic.sql.SqlColumn;
import org.mybatis.dynamic.sql.insert.InsertDSL;
import org.mybatis.dynamic.sql.insert.MultiRowInsertDSL;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateModel;

@Data
@EqualsAndHashCode(callSuper = true)
public class PriceData extends BasicsDomain<Long, PriceData> {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("price_type")
    private Integer priceType;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("date")
    private LocalDateTime date;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("value")
    private BigDecimal value;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("biz_date")
    private String bizDate;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("source")
    private String source;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("create_dept")
    private Long createDept;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("create_time")
    private LocalDateTime createTime;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("update_time")
    private LocalDateTime updateTime;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("tenant_id")
    private String tenantId;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("org_code")
    private String orgCode;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("day_ahead_price_lag_hours")
    private Integer dayAheadPriceLagHours;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("real_time_price_lag_hours")
    private Integer realTimePriceLagHours;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("real_time_exog_lag_hours")
    private Integer realTimeExogLagHours;

    private static final Table table = new Table();

    public static final String FIELD_ID = "id";

    public static final String FIELD_PRICE_TYPE = "priceType";

    public static final String FIELD_DATE = "date";

    public static final String FIELD_VALUE = "value";

    public static final String FIELD_BIZ_DATE = "bizDate";

    public static final String FIELD_SOURCE = "source";

    public static final String FIELD_CREATE_DEPT = "createDept";

    public static final String FIELD_CREATE_BY = "createBy";

    public static final String FIELD_CREATE_TIME = "createTime";

    public static final String FIELD_UPDATE_BY = "updateBy";

    public static final String FIELD_UPDATE_TIME = "updateTime";

    public static final String FIELD_TENANT_ID = "tenantId";

    public static final String FIELD_ORG_CODE = "orgCode";

    public static final String FIELD_DAY_AHEAD_PRICE_LAG_HOURS = "dayAheadPriceLagHours";

    public static final String FIELD_REAL_TIME_PRICE_LAG_HOURS = "realTimePriceLagHours";

    public static final String FIELD_REAL_TIME_EXOG_LAG_HOURS = "realTimeExogLagHours";

    public static final SqlColumn<Long> column_id = table.id;

    public static final SqlColumn<Integer> column_priceType = table.priceType;

    public static final SqlColumn<LocalDateTime> column_date = table.date;

    public static final SqlColumn<BigDecimal> column_value = table.value;

    public static final SqlColumn<String> column_bizDate = table.bizDate;

    public static final SqlColumn<String> column_source = table.source;

    public static final SqlColumn<Long> column_createDept = table.createDept;

    public static final SqlColumn<Long> column_createBy = table.createBy;

    public static final SqlColumn<LocalDateTime> column_createTime = table.createTime;

    public static final SqlColumn<Long> column_updateBy = table.updateBy;

    public static final SqlColumn<LocalDateTime> column_updateTime = table.updateTime;

    public static final SqlColumn<String> column_tenantId = table.tenantId;

    public static final SqlColumn<String> column_orgCode = table.orgCode;

    public static final SqlColumn<Integer> column_dayAheadPriceLagHours = table.dayAheadPriceLagHours;

    public static final SqlColumn<Integer> column_realTimePriceLagHours = table.realTimePriceLagHours;

    public static final SqlColumn<Integer> column_realTimeExogLagHours = table.realTimeExogLagHours;

    public static PriceData instance() {
        return new PriceData();
    }

    @Override
    public Table table() {
        return table;
    }

    @Override
    @SuppressWarnings("DuplicatedCode")
    public UnaryOperator<InsertDSL<PriceData>> insert() {
        return (InsertDSL<PriceData> dsl) -> {
            dsl.map(table.id).toProperty(FIELD_ID);
            dsl.map(table.priceType).toProperty(FIELD_PRICE_TYPE);
            dsl.map(table.date).toProperty(FIELD_DATE);
            dsl.map(table.value).toProperty(FIELD_VALUE);
            dsl.map(table.bizDate).toProperty(FIELD_BIZ_DATE);
            dsl.map(table.source).toProperty(FIELD_SOURCE);
            dsl.map(table.createDept).toProperty(FIELD_CREATE_DEPT);
            dsl.map(table.createBy).toProperty(FIELD_CREATE_BY);
            dsl.map(table.createTime).toProperty(FIELD_CREATE_TIME);
            dsl.map(table.updateBy).toProperty(FIELD_UPDATE_BY);
            dsl.map(table.updateTime).toProperty(FIELD_UPDATE_TIME);
            dsl.map(table.tenantId).toProperty(FIELD_TENANT_ID);
            dsl.map(table.orgCode).toProperty(FIELD_ORG_CODE);
            dsl.map(table.dayAheadPriceLagHours).toProperty(FIELD_DAY_AHEAD_PRICE_LAG_HOURS);
            dsl.map(table.realTimePriceLagHours).toProperty(FIELD_REAL_TIME_PRICE_LAG_HOURS);
            dsl.map(table.realTimeExogLagHours).toProperty(FIELD_REAL_TIME_EXOG_LAG_HOURS);
            return dsl;
        };
    }

    @Override
    @SuppressWarnings("DuplicatedCode")
    public UnaryOperator<MultiRowInsertDSL<PriceData>> insertMultiple() {
        return (MultiRowInsertDSL<PriceData> dsl) -> {
            dsl.map(table.id).toProperty(FIELD_ID);
            dsl.map(table.priceType).toProperty(FIELD_PRICE_TYPE);
            dsl.map(table.date).toProperty(FIELD_DATE);
            dsl.map(table.value).toProperty(FIELD_VALUE);
            dsl.map(table.bizDate).toProperty(FIELD_BIZ_DATE);
            dsl.map(table.source).toProperty(FIELD_SOURCE);
            dsl.map(table.createDept).toProperty(FIELD_CREATE_DEPT);
            dsl.map(table.createBy).toProperty(FIELD_CREATE_BY);
            dsl.map(table.createTime).toProperty(FIELD_CREATE_TIME);
            dsl.map(table.updateBy).toProperty(FIELD_UPDATE_BY);
            dsl.map(table.updateTime).toProperty(FIELD_UPDATE_TIME);
            dsl.map(table.tenantId).toProperty(FIELD_TENANT_ID);
            dsl.map(table.orgCode).toProperty(FIELD_ORG_CODE);
            dsl.map(table.dayAheadPriceLagHours).toProperty(FIELD_DAY_AHEAD_PRICE_LAG_HOURS);
            dsl.map(table.realTimePriceLagHours).toProperty(FIELD_REAL_TIME_PRICE_LAG_HOURS);
            dsl.map(table.realTimeExogLagHours).toProperty(FIELD_REAL_TIME_EXOG_LAG_HOURS);
            return dsl;
        };
    }

    @Override
    public void updateAllColumns(UpdateDSL<UpdateModel> dsl) {
        dsl.set(table.priceType).equalTo(this::getPriceType)
           .set(table.date).equalTo(this::getDate)
           .set(table.value).equalTo(this::getValue)
           .set(table.bizDate).equalTo(this::getBizDate)
           .set(table.source).equalTo(this::getSource)
           .set(table.createDept).equalTo(this::getCreateDept)
           .set(table.createBy).equalTo(this::getCreateBy)
           .set(table.createTime).equalTo(this::getCreateTime)
           .set(table.updateBy).equalTo(this::getUpdateBy)
           .set(table.updateTime).equalTo(this::getUpdateTime)
           .set(table.tenantId).equalTo(this::getTenantId)
           .set(table.orgCode).equalTo(this::getOrgCode)
           .set(table.dayAheadPriceLagHours).equalTo(this::getDayAheadPriceLagHours)
           .set(table.realTimePriceLagHours).equalTo(this::getRealTimePriceLagHours)
           .set(table.realTimeExogLagHours).equalTo(this::getRealTimeExogLagHours);
        if(Objects.nonNull(getId())) {
            dsl.where(table.id, SqlBuilder.isEqualTo(this::getId));
        }
    }

    @Override
    public void updateSelectiveColumns(UpdateDSL<UpdateModel> dsl) {
        dsl.set(table.priceType).equalToWhenPresent(this::getPriceType)
           .set(table.date).equalToWhenPresent(this::getDate)
           .set(table.value).equalToWhenPresent(this::getValue)
           .set(table.bizDate).equalToWhenPresent(this::getBizDate)
           .set(table.source).equalToWhenPresent(this::getSource)
           .set(table.createDept).equalToWhenPresent(this::getCreateDept)
           .set(table.createBy).equalToWhenPresent(this::getCreateBy)
           .set(table.createTime).equalToWhenPresent(this::getCreateTime)
           .set(table.updateBy).equalToWhenPresent(this::getUpdateBy)
           .set(table.updateTime).equalToWhenPresent(this::getUpdateTime)
           .set(table.tenantId).equalToWhenPresent(this::getTenantId)
           .set(table.orgCode).equalToWhenPresent(this::getOrgCode)
           .set(table.dayAheadPriceLagHours).equalToWhenPresent(this::getDayAheadPriceLagHours)
           .set(table.realTimePriceLagHours).equalToWhenPresent(this::getRealTimePriceLagHours)
           .set(table.realTimeExogLagHours).equalToWhenPresent(this::getRealTimeExogLagHours);
        if(Objects.nonNull(getId())) {
            dsl.where(table.id, SqlBuilder.isEqualTo(this::getId));
        }
    }

    @Override
    @SuppressWarnings("all")
    public SqlColumn[] columns() {
        return new SqlColumn[]{table.id, table.priceType, table.date, table.value, table.bizDate, table.source, table.createDept, table.createBy, table.createTime, table.updateBy, table.updateTime, table.tenantId, table.orgCode, table.dayAheadPriceLagHours, table.realTimePriceLagHours, table.realTimeExogLagHours};
    }

    @Override
    public SqlColumn<Long> id() {
        return table.id;
    }

    @Override
    public Map<String, SqlColumn<?>> columnsMap() {
        Map<String, SqlColumn<?>> maps = new LinkedHashMap<>(16);
        maps.put(FIELD_ID, table.id);
        maps.put(FIELD_PRICE_TYPE, table.priceType);
        maps.put(FIELD_DATE, table.date);
        maps.put(FIELD_VALUE, table.value);
        maps.put(FIELD_BIZ_DATE, table.bizDate);
        maps.put(FIELD_SOURCE, table.source);
        maps.put(FIELD_CREATE_DEPT, table.createDept);
        maps.put(FIELD_CREATE_BY, table.createBy);
        maps.put(FIELD_CREATE_TIME, table.createTime);
        maps.put(FIELD_UPDATE_BY, table.updateBy);
        maps.put(FIELD_UPDATE_TIME, table.updateTime);
        maps.put(FIELD_TENANT_ID, table.tenantId);
        maps.put(FIELD_ORG_CODE, table.orgCode);
        maps.put(FIELD_DAY_AHEAD_PRICE_LAG_HOURS, table.dayAheadPriceLagHours);
        maps.put(FIELD_REAL_TIME_PRICE_LAG_HOURS, table.realTimePriceLagHours);
        maps.put(FIELD_REAL_TIME_EXOG_LAG_HOURS, table.realTimeExogLagHours);
        return maps;
    }

    public static final class Table extends org.mybatis.dynamic.sql.AliasableSqlTable<Table> {
        public final SqlColumn<Long> id = column("id", JDBCType.BIGINT);

        public final SqlColumn<Integer> priceType = column("price_type", JDBCType.INTEGER);

        public final SqlColumn<LocalDateTime> date = column("date", JDBCType.TIMESTAMP);

        public final SqlColumn<BigDecimal> value = column("value", JDBCType.DECIMAL);

        public final SqlColumn<String> bizDate = column("biz_date", JDBCType.VARCHAR);

        public final SqlColumn<String> source = column("source", JDBCType.VARCHAR);

        public final SqlColumn<Long> createDept = column("create_dept", JDBCType.BIGINT);

        public final SqlColumn<Long> createBy = column("create_by", JDBCType.BIGINT);

        public final SqlColumn<LocalDateTime> createTime = column("create_time", JDBCType.TIMESTAMP);

        public final SqlColumn<Long> updateBy = column("update_by", JDBCType.BIGINT);

        public final SqlColumn<LocalDateTime> updateTime = column("update_time", JDBCType.TIMESTAMP);

        public final SqlColumn<String> tenantId = column("tenant_id", JDBCType.VARCHAR);

        public final SqlColumn<String> orgCode = column("org_code", JDBCType.VARCHAR);

        public final SqlColumn<Integer> dayAheadPriceLagHours = column("day_ahead_price_lag_hours", JDBCType.INTEGER);

        public final SqlColumn<Integer> realTimePriceLagHours = column("real_time_price_lag_hours", JDBCType.INTEGER);

        public final SqlColumn<Integer> realTimeExogLagHours = column("real_time_exog_lag_hours", JDBCType.INTEGER);

        public Table() {
            super("es_price_data", Table::new);
        }
    }
}